import { NextResponse, type NextRequest } from "next/server";

import { MiddlewareFunction } from "./util/chain";

export const proxyMiddleware = (req: NextRequest) => {
  const destination = new URL("https://www.baidu.com/");
  const url = req.nextUrl.clone();

  url.host = destination.host;
  url.protocol = destination.protocol;
  url.port = destination.port;
  url.pathname = "/";
  return NextResponse.rewrite(url);
};

export const handleProxyMiddleware: MiddlewareFunction = async (
  req,
  next,
  event
) => {
  if (req.nextUrl.pathname.startsWith(`/antd_demo`)) {
    // return proxyMiddleware(req);
    // console.log(req.nextUrl);
    return NextResponse.next();
  }
  return next();
};
